package com.negativeplus.negativeplusscanner;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;

public class DialogManager {
	private static ProgressDialog mProgressDialog;
	
	private static boolean okPressed;
	public static void showOKDialog(Activity activity, final boolean waitForOk, String title, String message)
	{
		okPressed = !waitForOk;
		final AlertDialog.Builder messageBuilder =new AlertDialog.Builder(activity);
		messageBuilder.setMessage(message);
		messageBuilder.setTitle(title);
		messageBuilder.setPositiveButton(activity.getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				okPressed = true;
			}
		});
		activity.runOnUiThread(new Runnable() {
			public void run() {
				AlertDialog dialog = messageBuilder.create();
				dialog.setCanceledOnTouchOutside(false);
				dialog.show();
			}
		});
		while(okPressed == false);
				
	}
	
	public static void showLoadingDialog (Activity activity){
		
		mProgressDialog = new ProgressDialog(activity);
		mProgressDialog.setMessage(activity.getString(com.negativeplus.negativeplusscanner.R.string.loading));
		mProgressDialog.setCanceledOnTouchOutside(false);
		mProgressDialog.show();
	}
	
	public static void dismissLoadingDialog (){
		mProgressDialog.dismiss();
	}
}
